package compiler;

import checker.Checker;
import checker.SemanticException;
import parser.Parser;
import parser.SyntacticException;
import util.AST.AST;
import util.symbolsTable.IdentificationTable;

/**
 * Compiler driver
 * 
 * @version 2010-september-04
 * @discipline Compiladores
 * @author Gustavo H P Carvalho
 * @email gustavohpcarvalho@ecomp.poli.br
 */
public class SubCCompiler {

	// Compiler identification table
	public static IdentificationTable identificationTable = null;

	/**
	 * Compiler start point
	 * 
	 * @param args
	 *            - none
	 */
	public static void main(String[] args) throws SyntacticException {
		// Initializes the identification table with the reserved words
		SubCCompiler.initIdentificationTable();

		// Creates the parser object
		Parser p = new Parser();

		// Creates the AST object
		AST astRoot = null;
		
		// Parses the source code
		try {
			astRoot = p.parse();
			
			if (astRoot != null) {
				System.out.println("\n-- AST STRUCTURE --");
				System.out.println(astRoot.toString(0));
			}
			
			Checker check = new Checker();
			check.check( (util.AST.Program) astRoot);
		} catch (SemanticException e){
			e.printStackTrace();
		}
		
	}

	/**
	 * Initializes the identification table with the reserved words
	 */
	private static void initIdentificationTable() {
		// Calls the initializer methods
		SubCCompiler.identificationTable = new IdentificationTable();
	}

}
